import { getModelForClass } from '@typegoose/typegoose';
import { ModelType } from '@typegoose/typegoose/lib/types';
import * as mongoose from 'mongoose';
import { WebUserModel } from './webUser.models';

/* 初始化后台账户 */
(async () => {
    await mongoose.connect(process.env.MONGODB || 'mongodb://127.0.0.1:27017/recruitment', { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true });
    const userModel: ModelType<WebUserModel> = getModelForClass(WebUserModel);
    const usermodel: WebUserModel = {
        name: 'admin',
        password: 'admin',
        logintime: Math.floor(Date.now() / 1000),
        regtime: Math.floor(Date.now() / 1000),
        loginip: "127.0.0.1",
    };
    try { await userModel.create(usermodel as WebUserModel) } catch (error) { };
})()